//
//  AppDelegate.swift
//  SwiftBase
//
//  Created by Wei Zhang on 2022/3/9.
//

import UIKit
import IQKeyboardManagerSwift
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        
        IQKeyboardManager.shared.enable = true
        IQKeyboardManager.shared.enableAutoToolbar = true
        
        window = UIWindow(frame: UIScreen.main.bounds)
        let loadingCont = UIStoryboard(name: "Login", bundle: nil).instantiateViewController(withIdentifier: "LoadingViewController")
        window?.rootViewController = loadingCont
        window?.makeKeyAndVisible()
        
        //通知
        NotificationCenter.default.addObserver(self, selector: #selector(login), name: NSNotification.Name(rawValue: kLOGIN_SUCCESS), object: nil)
        NotificationCenter.default.addObserver(self, selector: #selector(logout), name: NSNotification.Name(rawValue: kLOGOUT), object: nil)
        return true
    }
    
    @objc func logout(_ sender : Notification){
        userDefaults.set(nil, forKey: kTOKEN)
        let loginCont : LoginViewController = UIStoryboard(name: "Login", bundle: nil).instantiateViewController(withIdentifier: "LoginViewController") as! LoginViewController
        let nav = ZWNavigationController.init(rootViewController: loginCont)
        window?.rootViewController = nav
    }
    
    @objc func login(_ sender : Notification){
        let tabbarCont = ZWTabBarController()
        window?.rootViewController = tabbarCont
    }

}


